package kr.co.tomatosystem.pde.tools.internal.marker;

import org.eclipse.core.resources.IMarker;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.ltk.ui.refactoring.resource.RenameResourceWizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IMarkerResolution;

public class RenameResolution implements IMarkerResolution {

	@Override
	public String getLabel() {
		return "Rename Resource";
	}

	@Override
	public void run(final IMarker marker) {
		Display.getDefault().syncExec(new Runnable() {
			@Override
			public void run() {
				runInUIThread(marker);
			}
		});
	}

	protected void runInUIThread(IMarker marker) {
		RenameResourceWizard refactoringWizard = new RenameResourceWizard(marker.getResource());
		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(refactoringWizard);
		try {
			op.run(Display.getCurrent().getActiveShell(), "Rename Resource");
		} catch (InterruptedException e) {
			// do nothing
		}
	}
}
